package serialComm;

public class ResponseText extends SerialSms {
	private String returnCode;
	private String action;
	private String number;
	private String date;
	private String time;
	private String actualData;
	
	ResponseText() throws StringIndexOutOfBoundsException {
		try {
			System.out.println("Inside Response Text :");
			String[] datas = this.response.split(",");
			for(int i=0;i<datas.length;i++) {
				if(datas[i].indexOf("\r\r\n")>0) {
					int pos = datas[i].indexOf("\r\r\n");
					datas[i] = datas[i].substring(pos+3,datas[i].length());
					datas[i]=datas[i].replace(" ","#");
					datas[i]=datas[i].replace("\""," ");
					datas[i]=datas[i].trim();
					datas[i]=datas[i].replace("#"," ");
				}
				else {
					datas[i]=datas[i].replace(" ","#");
					datas[i]=datas[i].replace("\""," ");
					datas[i]=datas[i].trim();
					datas[i]=datas[i].replace("#"," ");
					
				}
			}		
			
			if(datas.length>0) {
				int pos;
				pos = datas[0].indexOf(": ");
				returnCode = datas[0].substring(pos+3,datas[0].length());
				action = datas[0].substring(0,pos);
				
				number = datas[1];
				date = datas[3];
				
				pos = datas[4].indexOf("\r\n");
				time = datas[4].substring(0,pos+2);
				actualData  = datas[4].substring(pos+2,datas[4].length());

			}

			setOnlyMessage();
		}catch(StringIndexOutOfBoundsException e) {
			String datas = " ";
		}
		
	
	}
	
	private void setOnlyMessage() {
		int p;
		p = response.indexOf("+20\"");
		actualData = response.substring(p+4,response.length());
		actualData = actualData.replace("\n"," ");
		actualData = actualData.replace("\r"," ");
		actualData = actualData.trim();
	}
	
	public String getReturnCode() {
		return this.returnCode;
	}
	
	public String getAction() {
		return this.action;
	}
	
	public String getNumber() {
		return this.number;
	}
	
	public String getDate() {
		return this.date;
	}
	
	public String getTime() {
		return this.time;
	}
	
	public String getActualData() {
		return this.actualData;
	}
	
}
